#include <time.h>
#include "mysig.h"

static time_t mytime;
static void my_handler(int);
static char *curtime();

void (*signal(int, void (*) (int))) (int);

int main() {
    signal(SIGALRM, my_handler);
    printf("set alarm in main to 10s %s", curtime());
    alarm(10);
    sleep(3);
    printf("reset alarm (return value: %d) %s", alarm(10), curtime());
    sleep(10000);
    return 0;
}

void my_handler(int sig) {
    printf("receive sig %d %s", sig, curtime());
    printf("reset alarm (return value: %d) %s", alarm(10), curtime());
}

static char *curtime() {
    mytime = time(NULL);
    return ctime(&mytime);
}
